local jueduiyz = fk.CreateSkill {
    name = "jueduiyz",
}

Fk:loadTranslationTable{
  ["jueduiyz"] = "绝对意志",
  ["$jueduiyz1"] = "（盾牌召回）",
  ["$jueduiyz2"] = "（盾牌举盾）",
  [":jueduiyz"] = "游戏开始时，你获得<a href=':progoldsheild'>【振金盾牌】</a>，你受到或造成伤害时，若你手牌中有<a href=':progoldsheild'>【振金盾牌】</a>，你可将<a href=':progoldsheild'>【振金盾牌】</a>置入你的装备区；你指定其他角色为目标后，若其装备区内有<a href=':progoldsheild'>【振金盾牌】</a>，你可获得之。",
  ["#jueduiyz-invoke"] = "绝对意志：你可以将【振金盾牌】置入你的装备区",
  ["#jueduiyz-invoke2"] = "绝对意志：你可以获得 %dest 装备区内的【振金盾牌】",
}

local progoldsheild = {{"progoldsheild", Card.Diamond, 13}}
local U = require "packages.utility.utility"

jueduiyz:addEffect(fk.GameStart, {
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
      return  player:hasSkill(jueduiyz.name)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local engine = table.find(U.prepareDeriveCards(room, progoldsheild, "progoldsheild"), function (id)
        return room:getCardArea(id) == Card.Void
        end)
        if engine then
            room:obtainCard(player, Fk:getCardById(engine), true)
        end
    end,
})

jueduiyz:addEffect(fk.DamageCaused, {
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(jueduiyz.name) and target == player then
            local has_hammer = false
            for _, id in ipairs(player:getCardIds{Player.Hand}) do
                if Fk:getCardById(id).name == "progoldsheild" then
                    has_hammer = true
                    break
                end
            end
            return has_hammer
        end  
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, {
            skill_name = jueduiyz.name,
            prompt = "#jueduiyz-invoke",
        })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = table.filter(player:getCardIds(Player.Hand), function(id)
            return Fk:getCardById(id).name == "progoldsheild"
        end)
        if #cards > 0 then
			room:moveCardIntoEquip(player, cards, jueduiyz.name, true, player)
		end
    end,
})

jueduiyz:addEffect(fk.DamageInflicted, {
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(jueduiyz.name) and target == player then
            local has_hammer = false
            for _, id in ipairs(player:getCardIds{Player.Hand}) do
                if Fk:getCardById(id).name == "progoldsheild" then
                    has_hammer = true
                    break
                end
            end
            return has_hammer
        end  
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, {
            skill_name = jueduiyz.name,
            prompt = "#jueduiyz-invoke",
        })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = table.filter(player:getCardIds(Player.Hand), function(id)
            return Fk:getCardById(id).name == "progoldsheild"
        end)
        if #cards > 0 then
			room:moveCardIntoEquip(player, cards, jueduiyz.name, true, player)
		end
    end,
})

jueduiyz:addEffect(fk.TargetSpecified, {
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(jueduiyz.name) and data.to ~= player then
            local has_hammer = false
            for _, id in ipairs(data.to:getCardIds{Player.Equip}) do
                if Fk:getCardById(id).name == "progoldsheild" then
                    has_hammer = true
                    break
                end
            end
            return has_hammer
        end  
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, {
            skill_name = jueduiyz.name,
            prompt = "#jueduiyz-invoke2::" .. data.to.id ,
        })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = table.filter(data.to:getCardIds(Player.Equip), function(id)
            return Fk:getCardById(id).name == "progoldsheild"
        end)
        if #cards > 0 then
			room:obtainCard(player, Fk:getCardById(cards[1]), true,fk.ReasonPrey,player,jueduiyz.name)
		end
    end,
})

return jueduiyz 